//! Party相关的数据模型定义
//! 基于OFBiz party-entitymodel.xml中的实体定义

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

pub mod party;
pub mod party_relationship;
pub mod contact;
pub mod view_entities;

pub use party::*;
pub use party_relationship::*;
pub use contact::*;
pub use view_entities::*;

/// 通用的数据行类型，用于存储实体数据
pub type DataRow = HashMap<String, String>;

/// 查询条件
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QueryCondition {
    pub field: String,
    pub operator: String,
    pub value: String,
    pub logic: String,
}

impl From<QueryCondition> for crate::entity_service::QueryCondition {
    fn from(condition: QueryCondition) -> Self {
        crate::entity_service::QueryCondition {
            field: condition.field,
            operator: condition.operator,
            value: condition.value,
            logic: condition.logic,
        }
    }
}

impl From<crate::entity_service::QueryCondition> for QueryCondition {
    fn from(condition: crate::entity_service::QueryCondition) -> Self {
        QueryCondition {
            field: condition.field,
            operator: condition.operator,
            value: condition.value,
            logic: condition.logic,
        }
    }
}

/// 查询参数
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QueryParams {
    pub entity_name: String,
    pub conditions: Vec<QueryCondition>,
    pub order_by: Vec<String>,
    pub limit: Option<i32>,
    pub offset: Option<i32>,
}

/// 插入/更新数据的参数
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DataParams {
    pub entity_name: String,
    pub data: DataRow,
}

/// 删除数据的参数
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeleteParams {
    pub entity_name: String,
    pub conditions: Vec<QueryCondition>,
}